<?php

declare(strict_types=1);

namespace App\Entity;

use App\Models\HomepageRecommend;

class HomepageRecommendEntity extends ABaseEntity
{
    public $id          = 0;
    public $text1       = '';
    public $text2       = '';
    public $text3       = '';
    public $text4       = '';
    public $text5       = '';
    public $image1      = '';
    public $image2      = '';
    public $image3      = '';
    public $image4      = '';
    public $image5      = '';
    public $link_url    = '';
    public $city_id     = 0;
    public $product_id  = 0;
    public $sort_weight = 0;
    public $hidden      = 0;

    public function __construct(HomepageRecommend $model)
    {
        $this->model = $model;
        $this->entitySetData();
    }

    public function modelSetData(array $recommend): void
    {
        if (isset($recommend['id'])) {
            $this->setId($recommend['id']);
        }
        for ($i = 1; $i <= 5; $i++) {
            if (isset($recommend['text' . $i])) {
                $this->setText($i, $recommend['text' . $i]);
            }
        }
        for ($i = 1; $i <= 5; $i++) {
            if (isset($recommend['image' . $i])) {
                $this->setImage($i, $recommend['image' . $i]);
            }
        }
        if (isset($recommend['link_url'])) {
            $this->setLinkUrl($recommend['link_url']);
        }
        if (isset($recommend['product_id'])) {
            $this->setProductId($recommend['product_id']);
        }
        if (isset($recommend['city_id'])) {
            $this->setCityId($recommend['city_id']);
        }
        if (isset($recommend['sort_weight'])) {
            $this->setSortWeight($recommend['sort_weight']);
        }
        if (isset($recommend['hidden'])) {
            $this->setHidden($recommend['hidden']);
        }
    }

    public function entitySetData(): void
    {
        if ($id = $this->getId()) {
            $this->id = $id;
        }
        for ($i = 1; $i <= 5; $i++) {
            $textName          = 'text' . $i;
            $this->{$textName} = $this->getText($i);
        }
        for ($i = 1; $i <= 5; $i++) {
            $imageName          = 'image' . $i;
            $this->{$imageName} = $this->getImage($i);
        }
        $this->link_url    = $this->getLinkUrl();
        $this->city_id     = $this->getCityId();
        $this->product_id  = $this->getProductId();
        $this->sort_weight = $this->getSortWeight();
        $this->hidden      = $this->getHidden();
    }

    public function getId(): int
    {
        return $this->model->id ?? 0;
    }

    public function getText(int $textNo): string
    {
        $textName = 'text' . $textNo;

        return $this->model->{$textName} ?: '';
    }

    public function getImage(int $imageNo): string
    {
        $imageName = 'image' . $imageNo;

        return $this->model->{$imageName} ?: '';
    }

    public function getLinkUrl(): string
    {
        return $this->model->link_url ?: '';
    }

    public function getCityId(): int
    {
        return $this->model->city_id ?: 0;
    }

    public function getProductId(): int
    {
        return $this->model->product_id ?: 0;
    }

    public function getSortWeight(): int
    {
        return $this->model->sort_weight ?: 0;
    }

    public function getHidden(): int
    {
        return $this->model->hidden ?: 0;
    }

    public function setId(int $id): void
    {
        $this->model->id = $id;
    }

    public function setText(int $no, string $val): void
    {
        $textName                 = 'text' . $no;
        $this->model->{$textName} = $val;
    }

    public function setImage(int $no, string $val): void
    {
        $imageName                 = 'image' . $no;
        $this->model->{$imageName} = $val;
    }

    public function setLinkUrl(string $val): void
    {
        $this->model->link_url = $val;
    }

    public function setCityId($val): void
    {
        $this->model->city_id = intval($val);
    }

    public function setProductId($productId): void
    {
        $this->model->product_id = intval($productId);
    }

    public function setSortWeight($val): void
    {
        $this->model->sort_weight = intval($val);
    }

    public function setHidden($val): void
    {
        $this->model->hidden = intval($val);
    }
}
